﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MapLibrary.Particles;
using MapLibrary.Players.CollisionResponse;
using MapLibrary.CollisionResponse;

using MapLibrary.Players.Abilities.MapLibrary.Players.Skills;
namespace MapLibrary.Players
{
    using CollisionCategory = CollisionResponseManager.CollisionCategory;

    public class ProteinParticle : Particle
    {

        //Different possible protein types
        public enum ProteinType
        {
            A,
            B,
            C
        }

        public const int PROTEIN_LIFETIME = 1200;

        private ProteinType type;
        private int amount;

        public ProteinParticle(ProteinType type, int amountOfProtein)
            : base()
        {
            this.type = type;
            this.amount = amountOfProtein;

            InitCollisionData();

            Hookable = false;
        }

        public ProteinParticle()
            : base()
        {
            this.type = ProteinType.A;
            this.amount = 10;

            InitCollisionData();

            Hookable = false;
        }

        public int AmountOfProtein
        {
            get { return amount; }
            set { amount = value; }
        }

        public ProteinType TypeOfProtein
        {
            get { return type; }
            set { type = value; SetState();  }
        }

        public override bool MyOnCollision(FarseerPhysics.Dynamics.Fixture f1, FarseerPhysics.Dynamics.Fixture f2, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            bool ret = base.MyOnCollision(f1, f2, contact);

            /*Player p = f2.Body.UserData as Player;
            if (p != null)
            {
                if (type == ProteinType.A)
                {
                    p.AddProtein(0, amount);
                }
                else if (type == ProteinType.B)
                {
                    p.AddProtein(1, amount);
                }
                else if (type == ProteinType.C)
                {
                    p.AddProtein(2, amount);
                }
            }
            */
            LevelCollisionRegion region = f2.Body.UserData as LevelCollisionRegion;
            if (region != null)
                return false;

            Hook h = f2.Body.UserData as Hook;
            if (h != null)
                return false;

            return ret;
        }


        private void InitCollisionData()
        {
            CollisionAction generalResponse = new CollisionAction(CollisionCategory.All, false);

            CollisionAction playerResponse = new CollisionAction(CollisionCategory.Player, false);
            playerResponse.Behaviors.Add(new ProteinPlayerBehavior(this));

            collisionManager.AddCollisionAction(CollisionCategory.All, generalResponse);
            collisionManager.AddCollisionAction(CollisionCategory.Player, playerResponse);
        }

        private void SetState()
        {
            if (base.Type != null)
            {
                if (type == ProteinType.A)
                    base.Type.CurrentState = "ProteinA";
                else if (type == ProteinType.B)
                    base.Type.CurrentState = "ProteinB";
                else
                    base.Type.CurrentState = "ProteinC";
            }
        }
    }
}
